<?php
namespace slinks\extensions\aop\interceptors;

use slinks\extensions\aop\core\IInterceptor;

class LoggingInterceptor implements IInterceptor{
	
	/* @var Logger $log */
	private $log;
	
	function __construct($timeZone,$configFile){
		date_default_timezone_set($timeZone);
		\Logger::configure($configFile);
		$this->log = \Logger::getLogger(__CLASS__);
	}
	
	/**
	 * Called prior to executing the intercepted method.
	 * 
	 * @param String $className is the className of the class whose method is being executed.
	 * @param String $methodName is the name of the method being called.
	 * @param array $arguments is an enumerated array containing the parameters passed to the $name'ed method.
	 */
	public function before($className,$methodName,$arguments){
		if($this->log->isDebugEnabled()){
			$this->log->debug('Executing: '.$className.'.'.$methodName);
		}
	}
	
	public function exception($className,$methodName,$arguments, \Exception $exception){
		if($this->log->isDebugEnabled()){
			$this->log->debug('Error: '.$className.'.'.$methodName.' '.$exception->getMessage());
		}
	}
	
	/**
	 * Called after executing the intercepted method.
	 * 
	 * @param String $className is the className of the class whose method is being executed.
	 * @param String $methodName is the name of the method being called.
	 * @param array $arguments is an enumerated array containing the parameters passed to the $name'ed method.
	 * @param $return the value returned from the intercepted method.
	 */
	public function after($className,$methodName,$arguments,$return=null){
//		if($this->log->isDebugEnabled()){
//			$this->log->debug('Finished: '.$className.'.'.methodName);
//		}
	}
}